//
//  HUDTool.m
//  wentong
//
//  Created by xieyingze on 15/12/7.
//  Copyright © 2015年 xieyingze. All rights reserved.
//

#import "HUDTool.h"

@interface HUDTool ()

@property (nonatomic, strong) MBProgressHUD *HUD;
@end

@implementation HUDTool

+ (instancetype)shareInstance
{
    static HUDTool *manager = nil;
    @synchronized(self) {
        if (!manager) {
            manager = [[self alloc] init];
        }
    }
    return manager;
}

- (void)showMsg:(NSString *)msg inView:(UIView *)view
{
    self.HUD = [[MBProgressHUD alloc] initWithView:view];
    [view addSubview:self.HUD];
    
    self.HUD.dimBackground = YES;
    self.HUD.square = YES;
    self.HUD.labelText = msg;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.HUD show:YES];
    });
}

- (void)hidHUD
{
    if (self.HUD) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.HUD hide:YES];
        });
    }
}

- (void)showSoonRealMsg:(NSString *)msg inView:(UIView *)view
{
    if (self.HUD) {
        [self.HUD removeFromSuperview];
        self.HUD = nil;
    }
    self.HUD = [[MBProgressHUD alloc] initWithView:view];
    [view addSubview:self.HUD];
    
    self.HUD.mode = MBProgressHUDModeText;
    self.HUD.detailsLabelText = msg;
    
    [self.HUD show:YES];
    [self.HUD hide:YES afterDelay:1.5];
}

- (void)showSoonMsg:(NSString *)msg inView:(UIView *)view
{
    self.HUD = [[MBProgressHUD alloc] initWithView:view];
    [view addSubview:self.HUD];
    
    self.HUD.dimBackground = YES;
    self.HUD.square = YES;
    self.HUD.labelText = msg;
    
    [self.HUD show:YES];
    [self.HUD hide:YES afterDelay:1.5];
}

@end
